home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / g4c / ced / cedbar.gc < prev    next >
Text File  |  1999-04-29  |  16KB  |  600 lines

  1. G4C
  2.  
  3. ; $VER: CedBar.gc 3.5 ( by dck - 20.8.98 )
  4. ; ----------------------------------------------------------------------
  5. ; A GUI providing a toolbar for the CygnusEd text editor.
  6. ; This is a work in perpetual progress, as I use it myself..
  7. ; CygnusEd is a commercial product from ASDG Inc. (AFAIK)
  8.  
  9. ; What we do is define various icons, which we use as if they 
  10. ; were buttons and send the appropriate rexx command to $cedport, 
  11. ; which contains the name of the current CEd's arexx port.
  12.  
  13. ; According to your monitor/resolution/font etc the Icon-buttons may 
  14. ; seem too small or too big - just redesign them to your liking.
  15.  
  16. ; =======================================================================
  17.  
  18. WINBIG -1 0 625 14 "" ; note : no title - since don't want borders
  19. WinType 000010
  20. ; winbackground pattern 3 2 ; try it..
  21. varpath 'cedbar.g/cedmark.g'
  22. UseTopaz        ; because it's a non-resizable window
  23.  
  24. ; -----------------------------------------------------------
  25. ;       on loading
  26. ; -----------------------------------------------------------
  27.  
  28. xOnLoad
  29.  
  30. TTget :cedbar.gc        ; read in out icon's tool types
  31. if $CEDPATH > ' '        ; tells us the full path of ced
  32.    cedname = $CEDPATH
  33. else
  34.    cedname = CEd        ; << *** PUT HERE THE FULL PATH OF CED ***
  35. endif
  36.  
  37. cedClip = 0
  38. cedMark = 1
  39. cedSend = ""
  40. cedFile = ""
  41. newflag = 0
  42. Update cedbar.gc 1 $cedClip
  43. setgad cedbar.gc 20 HIDE     ; hide listview
  44. setgad cedbar.gc 11/12 HIDE    ; hide amiga guide & launch mode icons
  45. barmode = NORMAL        ; or GUIDE - can add more..
  46. GuiClose cedbar.g          ; Close the small window (if it was open)
  47.  
  48. gosub cedbar.gc StartUpCed      ; See which ced is calling us
  49. if $$sys.fsn[0][6] != 'Cygnus'  ; if we are called from an other screen
  50.    cedscreen = CygnusEdScreen   ; get the 1st ced's screen name
  51.    instance = $cedport[-1][1]
  52.    if $instance > 0
  53.    and $instance <= 9
  54.        appvar cedscreen $($instance + 1) 
  55.    else
  56.        appvar cedscreen 1 
  57.    endif
  58.    guiscreen #$cedscreen front  ; force ced to front
  59. endif
  60. GuiOpen  cedbar.gc
  61.  
  62. GuiLoad :cedbar.g        ; the small bar
  63. GuiLoad :cedMark.g        ; the Mark Set/Go window
  64. GuiLoad :cedclip.g        ; clipboard viewer
  65. guiload guis:tools/filereq.gc   ; the file requester
  66.  
  67. ; see under which ced we're running..
  68. info gui cedbar.gc
  69. cedscreen = $$win.screen
  70. cedport = rexx_ced
  71. if $cedscreen[0][6] == 'Cygnus'   ; make sure it's a ced pubscreen
  72.    instance = $cedscreen[-1][1]   ; get last letter
  73.    if $instance > 1
  74.    and $instance <= 9          ; adjust port name (if needed)
  75.        appvar cedport $($instance - 1) 
  76.    endif
  77. endif
  78.  
  79. ; find & load the Gui4Cli extension which provides us with 
  80. ; extra commands we can use with the CALL command
  81. ifexists port LVFormat
  82.    call LVFormat Register         ; notify it that we want it too
  83. else
  84.    ; look in our dir..
  85.    extract cedbar.gc guipath mypath
  86.    joinfile $mypath lvformat progname
  87.    joinfile $progname lvformat progname
  88.    ifexists file $progname
  89.       run $progname
  90.    elseifexists file guis:ext/lvformat/lvformat
  91.       run guis:ext/lvformat/lvformat
  92.    else
  93.       ezreq 'Could not find LVFormat!' OK ''
  94.    endif
  95. endif
  96.  
  97. ; -----------------------------------------------------------
  98. ;       ending events
  99. ; -----------------------------------------------------------
  100.  
  101. xONQuit
  102. GuiQuit cedbar.g        ; unload all the other GUIs
  103. GuiQuit cedmark.g
  104. guiquit cedclip.g
  105. guiquit addlink.g
  106. guiquit addeffect.g
  107. guiquit addnode.g
  108. guiquit indent.g
  109. guiquit wrap.g
  110. guiquit filereq.gc
  111. ifexists port LVFormat    ; quit out handler
  112.    call LVFormat quit
  113. endif
  114. ifexists file t:tempnode
  115.    delete t:tempnode
  116. endif
  117.  
  118. xonfail
  119. guiwindow cedbar.gc resume
  120.  
  121. ; -----------------------------------------------------------
  122. ;       Routine - Find ced
  123. ; -----------------------------------------------------------
  124.  
  125. xRoutine StartUpCed
  126. local count
  127. count = 1
  128.  
  129. portname = rexx_ced
  130.  
  131. ; look for any instance of ced
  132. ifexists port ~rexx_ced
  133.    while $count < 10
  134.       IfExists PORT 'rexx_ced$count'
  135.          portname = 'rexx_ced$count'
  136.          return
  137.       endif
  138.       ++count
  139.    endwhile
  140. else
  141.    return
  142. endif
  143.  
  144. run '$cedname'        ; not found - start it up
  145. Wait PORT rexx_ced 30   ; wait for ced to load
  146. if $$RETCODE > 0
  147.    ezreq "CygnusEd was not found!\nPlease enter the full path & name of\nthe CygnusEd program in the Icon Tooltypes\nof the CedBar.gc icon." EXIT ""
  148.    GuiQuit cedbar.gc
  149.    Stop
  150. endif
  151. Wait SCREEN CygnusEdScreen1 30     ; if Screen does not open, use WB
  152. portname = rexx_ced
  153.  
  154. ; -----------------------------------------------------------
  155. ;       window handling events
  156. ; -----------------------------------------------------------
  157.  
  158. xOnRMB              ; rotate the last 8 buttons
  159. ; GuiClose cedbar.gc
  160. ; GuiOpen cedbar.g
  161. gosub cedbar.gc guichange
  162.  
  163. XICON 2 0 :icons/wnClose   ; the Q icon
  164. ezreq "Last chance..\nQuit ?" YES|CANCEL choice
  165. if $choice = 1
  166.    GuiQuit cedbar.gc
  167. endif
  168.  
  169. XICON 15 1 :icons/right    ; the > icon togle big/small windows
  170. GuiClose cedbar.gc
  171. GuiOpen cedbar.g
  172.  
  173. ; -----------------------------------------------------------
  174. ;       New file
  175. ; -----------------------------------------------------------
  176.  
  177. XICON 30 0 :icons/New
  178. SendRexx $cedport "open new"
  179.  
  180. ; -----------------------------------------------------------
  181. ;       Open file
  182. ; -----------------------------------------------------------
  183. ; ----- use "filereq.gc" (if it exists in our dir - else ASL)
  184.  
  185. XICON 55 0 :icons/Open
  186. newflag = 1     ; set flag to know that we pressed the open button
  187. ifexists file guis:tools/filereq.gc
  188.     ; get the current filename so we can get it's path
  189.     sendrexx $cedport 'status filename'
  190.     filename = $$rexxret
  191.     extract filename path path
  192.     ; load & open filereq.gc
  193.     guiload guis:tools/filereq.gc cedbar.gc LoadFile $cedbar.gc/path guis:tools/fav/CedFav
  194. else
  195.     ; if no filereq.gc open normally
  196.     SendRexx $cedport "open"
  197. endif
  198.  
  199. ; ----- the routine that will be called from filereq.gc for *every*
  200. ;       file chosen in it's listview
  201.  
  202. xroutine LoadFile filename
  203. ; if there have been changes made or it's an existing file - open a new file
  204.   sendrexx $cedport 'status numchanges'
  205.   changes = $$rexxret
  206.   if $newflag = 0
  207.   or $changes > 0
  208.      SendRexx $cedport "open new"
  209.   endif
  210.   newflag = 0   ; set flag = all next files (multiselected) => open new view
  211.   SendRexx $cedport 'open $filename'
  212.  
  213. ; ------ add current path to the filename - store it in cedbar.gc/fn
  214.  
  215. xroutine makefile fn
  216.   local pth
  217.   extract cedbar.gc guipath pth
  218.   joinfile $pth $fn fn
  219.  
  220.  
  221. ; -----------------------------------------------------------
  222. ;       View handling icons
  223. ; -----------------------------------------------------------
  224.  
  225. XICON 80 0 :icons/Big
  226.   SendRexx $cedport "expand view"
  227.  
  228. ; -----------------------------------------------------------
  229. ;       Save as.., Save
  230. ; -----------------------------------------------------------
  231.  
  232. XICON 95 0 :icons/saveas
  233. SendRexx $cedport "save as"
  234.  
  235. XICON 120 0 :icons/save
  236. SendRexx $cedport "save"
  237.  
  238. ; -----------------------------------------------------------
  239. ;       Quit
  240. ; -----------------------------------------------------------
  241.  
  242. XICON 145 0 :icons/quit
  243. ; get information
  244. sendrexx $cedport 'status numchanges'
  245. changes = $$rexxret
  246. sendrexx $cedport 'status filename'
  247. filename = $$rexxret
  248. sendrexx $cedport 'status totalnumviews'
  249. views = $$rexxret
  250. if $changes > 0
  251.    ezreq '$changes changes have been made.\nQuit $filename ?\n' 'Quit|Save & Quit|CANCEL' choice
  252.    if $choice = 0
  253.       stop
  254.    elseif $choice = 2
  255.       SendRexx $cedport "save"
  256.       ; we will quit later..
  257.    endif
  258. endif
  259. if $views = 1   ; this is the last file - give him one more chance..
  260.    ezreq 'Really quit ?' "Quit!|CANCEL" choice
  261.    if $choice = 0
  262.       stop
  263.    endif
  264.    ; the guy just won't listen to reason..
  265.    guiclose cedbar.gc   ; close window so ced can quit
  266.    guiclose cedmark.g
  267.    guiquit cedbar.gc    ; and quit.. (after all commands have executed)
  268. endif
  269. SendRexx $cedport "quit"
  270.  
  271. ; -----------------------------------------------------------
  272. ;       Cut & Paste
  273. ; -----------------------------------------------------------
  274.  
  275. XICON 170 0 :icons/cut
  276. SendRexx $cedport cut
  277. lvuse CedClip.g 1
  278. lvchange 'CLIPS:$cedClip'
  279.  
  280. XICON 195 0 :icons/copy
  281. SendRexx $cedport copy
  282. lvuse CedClip.g 1
  283. lvchange 'CLIPS:$cedClip'
  284.  
  285. XICON 220 0 :icons/paste
  286. SendRexx $cedport paste
  287. lvuse CedClip.g 1
  288. lvchange 'CLIPS:$cedClip'
  289.  
  290. ; -----------------------------------------------------------
  291. ;       Change the clipboard unit (use cedclip.g)
  292. ; -----------------------------------------------------------
  293.  
  294. XAREA 246 0 40 14 box   ; use an area gad to get button click over
  295. guiopen cedclip.g       ; the text gad below..
  296.  
  297. TEXT 246 1 40 12 "" 10 box    ; the number of the clipboard unit
  298. GadID 1
  299.  
  300. XICON 287 1 :icons/Up  ; the up/down icons
  301. ++cedClip
  302. gosub cedclip.g changeunit
  303.  
  304. XICON 287 7 :icons/Down
  305. --cedClip
  306. gosub cedclip.g changeunit
  307.  
  308. ; -----------------------------------------------------------
  309. ;       Undo/Redo, Find & Replace
  310. ; -----------------------------------------------------------
  311.  
  312. XICON 300 0 :icons/undo
  313. SendRexx $cedport "undo"
  314.  
  315. XICON 315 0 :icons/redo
  316. SendRexx $cedport "redo"
  317.  
  318. XICON 330 0 :icons/find
  319. SendRexx $cedport "search for"
  320.  
  321. XICON 356 1 :icons/right
  322. SendRexx $cedport "repeat search forwards"
  323.  
  324. XICON 370 0 :icons/replace
  325. SendRexx $cedport "replace"
  326.  
  327. XICON 396 1 :icons/right
  328. SendRexx $cedport "repeat replace"
  329.  
  330.  
  331. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  332. ;       change gui..
  333. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  334.  
  335. XICON 410 0 :icons/change
  336. gosub cedbar.gc guichange
  337.  
  338. xroutine guichange    ; also called from xOnRMB
  339. if $barmode = NORMAL
  340.    barmode = GUIDE
  341.    setgad cedbar.gc 10 HIDE
  342.    setgad cedbar.gc 12 HIDE
  343.    setgad cedbar.gc 11 SHOW
  344. elseif $barmode = GUIDE
  345.    barmode = LAUNCH
  346.    setgad cedbar.gc 10/11 HIDE
  347.    setgad cedbar.gc 12 SHOW
  348. else ; LAUNCH mode
  349.    barmode = NORMAL
  350.    setgad cedbar.gc 11/12 HIDE
  351.    setgad cedbar.gc 10 SHOW
  352. endif
  353. partredraw cedbar.gc 430 0 625 14
  354.  
  355.  
  356. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  357. ;    gadid 10
  358. ; ===========================================================
  359. ;    NORMAL mode
  360. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  361.  
  362. xICON 425 0 :icons/all
  363. gadid 10
  364. SendRexx $cedport "beg of file"
  365. SendRexx $cedport "mark"
  366. SendRexx $cedport "end of file"
  367.  
  368. xICON 450 0 :icons/goto
  369. gadid 10
  370. GuiOpen cedmark.g
  371.  
  372. xICON 475 0 :icons/clear
  373. gadid 10
  374. SendRexx $cedport "clear"
  375.  
  376. xICON 500 0 :icons/colmark
  377. gadid 10
  378. SendRexx $cedport "mark columnar"
  379.  
  380. xICON 525 0 :icons/brackets
  381. gadid 10
  382. SendRexx $cedport "find matching bracket"
  383.  
  384. xICON 550 0 :icons/print
  385. gadid 10
  386. SendRexx $cedport "print file"
  387.  
  388. xICON 575 0 :icons/empty
  389. gadid 10
  390.  
  391. xICON 600 0 :icons/nextced
  392. gadid 10
  393. guiclose cedbar.gc
  394. SendRexx $cedport "activate next ced"
  395. if $$rexxret > "0"     ;  if there is a next ced
  396.    cedport = $$rexxret ; the new port name
  397.    SendRexx $cedport "status pubscreenname"
  398.    cedscreen = $$rexxret
  399. endif
  400. guiopen cedbar.gc
  401.  
  402. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  403. ;    gadid 11
  404. ; ===========================================================
  405. ;    GUIDE mode - Amiga Guide editor
  406. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  407.  
  408. ;     create a new guide
  409. ; -----------------------------------------------------------
  410.  
  411. xICON 425 0 :icons/AGNew
  412. gadid 11
  413. guiload :addnode.g GUIDE
  414.  
  415. ; -----------------------------------------------------------
  416. ;     split an existing guide
  417. ; -----------------------------------------------------------
  418.  
  419. xICON 450 0 :icons/AGSplit
  420. gadid 11
  421. guiload :splitguide.g
  422.  
  423. ; -----------------------------------------------------------
  424. ;    join nodes into a guide
  425. ; -----------------------------------------------------------
  426.  
  427. xICON 475 0 :icons/AGJoin
  428. gadid 11
  429. guiload :joinguide.g
  430.  
  431. ; -----------------------------------------------------------
  432. ;    create new node
  433. ; -----------------------------------------------------------
  434.  
  435. xICON 500 0 :icons/AGNode
  436. gadid 11
  437. guiload :addnode.g NODE
  438.  
  439. ; -----------------------------------------------------------
  440. ;    make link
  441. ; -----------------------------------------------------------
  442.  
  443. xICON 525 0 :icons/AGLink
  444. gadid 11
  445. guiload :addlink.g
  446.  
  447. ; -----------------------------------------------------------
  448. ;    add effect
  449. ; -----------------------------------------------------------
  450.  
  451. xICON 550 0 :icons/AGfx
  452. gadid 11
  453. guiload :addeffect.g
  454.  
  455. ; -----------------------------------------------------------
  456. ;    mormalize selected text (i.e. remove @{..)
  457. ; -----------------------------------------------------------
  458.  
  459. xICON 575 0 :icons/AGClear
  460. gadid 11
  461. ; cut the selected text into our lv
  462. SendRexx $cedport cut
  463. lvuse CedClip.g 1
  464. lvchange 'CLIPS:$cedClip'
  465. ; ask the CedHandler program to process it
  466. call LVFormat agclean
  467.  
  468. ; paste it back into ced
  469. lvsave 'CLIPS:$cedClip'
  470. SendRexx $cedport paste
  471.  
  472. ; -----------------------------------------------------------
  473. ;    view this node
  474. ; -----------------------------------------------------------
  475.  
  476. xICON 600 0 :icons/eye
  477. gadid 11
  478. guiwindow cedmark.g wait
  479. ;  close previous window & file, if any
  480. ifexists port CEDGUIDE
  481.    sendrexx CEDGUIDE QUIT
  482. endif
  483. ; get current file name
  484. sendrexx $cedport 'status filename'
  485. filename = $$rexxret
  486. ; save file if it's been changed
  487. sendrexx $cedport 'status numchanges'
  488. if $$rexxret > 0
  489.    sendrexx $cedport 'save'
  490. endif
  491. ; load into lv, make it a node, save as tempnode & show it
  492. lvuse cedbar.gc 20
  493. lvchange $filename
  494. lvgo first
  495. if $$lv.rec[0][5] == "@data"
  496.    ; if it's a node add the @database stuff..
  497. else
  498.    lvinsert -1 '@database Test\n@node MAIN "Main"\n'
  499.    lvadd '@endnode\n'
  500. endif
  501. lvsave t:tempnode
  502. run 'amigaguide t:tempnode screen=$cedscreen port=CEDGUIDE'
  503. guiwindow cedmark.g resume
  504.  
  505.  
  506. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  507. ;    gadid 12
  508. ; ===========================================================
  509. ;    LAUNCH mode
  510. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  511.  
  512. xICON 425 0 :icons/indent
  513. gadid 12
  514. guiload :indent.g
  515.  
  516. xICON 450 0 :icons/unindent
  517. gadid 12
  518. SendRexx $cedport cut
  519. lvuse CedClip.g 1
  520. lvchange 'CLIPS:$cedClip'
  521. call LVFormat UnIndent
  522. lvsave 'CLIPS:$cedClip'
  523. SendRexx $cedport paste
  524.  
  525. xICON 475 0 :icons/wrap
  526. gadid 12
  527. guiload :wrap.g
  528.  
  529. ; ------------------------------- my temp stuff
  530. xICON 500 0 :icons/empty
  531.     gadid 12
  532.     ; get selected text
  533.     SendRexx $cedport cut
  534.     lvuse CedClip.g 1
  535.     lvchange 'CLIPS:$cedClip'
  536.     txt = $$lv.rec
  537.     sendrexx $cedport "text #define $txt\tMakeID (\'$txt[0][1]\',\'$txt[1][1]\',\'$txt[2][1]\',\'$txt[3][1]\')\t\t// "
  538.  
  539. xICON 525 0 :icons/empty
  540.     gadid 12
  541.     ; get selected text
  542.     SendRexx $cedport cut
  543.     lvuse CedClip.g 1
  544.     lvchange 'CLIPS:$cedClip'
  545.     txt = $$lv.rec
  546.     sendrexx $cedport 'text @{\" $txt \" link \"$txt\" }'
  547.  
  548. ; ------------------------------------------------
  549.  
  550. xICON 550 0 :icons/search
  551. gadid 12
  552. gosub cedbar.gc getname
  553. if $textpath < ' '
  554.    textpath = sys:
  555. endif
  556. ; put selected text into search for box
  557. SendRexx $cedport copy
  558. lvuse CedClip.g 1
  559. lvchange 'CLIPS:$cedClip'
  560. ; load a slightly modified version of guis:g4c/fsearch.gc
  561. guiload :fsearch.gc '$textpath' '$$lv.rec'
  562.  
  563. xICON 575 0 :icons/calc
  564. gadid 12
  565. ifexists file guis:tools/calc.gc
  566.     guiload guis:tools/calc.gc
  567. else
  568.     guiload :calc.gc
  569. endif
  570.  
  571. xICON 600 0 :icons/info
  572. gadid 12
  573. local path/guidename ; local vars
  574. ;  close previous guide if any
  575. ifexists port CEDGUIDE
  576.    sendrexx CEDGUIDE QUIT
  577. endif
  578. extract cedbar.gc guipath path
  579. joinfile $path CedBar.guide guidename
  580. run 'amigaguide $guidename screen=$cedscreen port=CEDGUIDE'
  581.  
  582. ; -----------------------------------------------------------
  583. ;     a hidden listview - used for file manipulation
  584. ; -----------------------------------------------------------
  585.  
  586. XLISTVIEW 0 0 87 110 '' lvr '' 0 MULTI
  587. gadid 20
  588.  
  589.  
  590. ; -----------------------------------------------------------
  591. ;     routine to get current filename & path
  592. ; -----------------------------------------------------------
  593.  
  594. xroutine getname
  595. sendrexx $cedport 'status filename'
  596. filename = $$rexxret
  597. extract filename path textpath
  598.  
  599.  
  600.